package com.cxb.java.face.threadLocal;

/**
 * @Classname Test
 * @Date 2023/9/10 17:56
 * @Created by Administrator
 * @Description TODO
 */
public class Test {

    private static ThreadLocal<Integer> threadLocal = ThreadLocal.withInitial(() -> 0);

  public static void main(String[] args) {
    threadLocal.set(42);

    Runnable task = () -> {
      int value = threadLocal.get();
      System.out.println("Thread-local value: " + value);
    };

    Thread thread1 = new Thread(task);
    Thread thread2 = new Thread(task);

    thread1.start();
    thread2.start();
  }
}
